/* Copyright 2009 Requirement Management System
 * 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.mags.dao.common;

import java.io.Serializable;
import java.sql.Blob;
import java.util.Collection;

/**
 * @author Mario Gait�n
 */
public interface DAO {
	public void setTransactionManager(Object transactionManager);
	public Object getTransactionTemplate();
	public Serializable create(Object record);
	public void createOrUpdate(Object record);
	public void update(Object record);
	public void delete(Object record);
	public Object getById(EntityDefinition entityDef, Serializable id);
	public Object getByIdForUpdate(EntityDefinition entityDef, Serializable id);
	public Number executeUpdate( String query,  Attribute[] attributes);
	public Number update(EntityDefinition entityDef, Attribute[] attributes, RestrictionBuilder restriction);	
	public Object createSubquery(EntityDefinition entityDef, String[] projections, RestrictionBuilder restriction);
	
	public Collection<?> executeQuery(String query,  Attribute[] attributes, Limits limits);
	public Collection<?> getByRestriction(EntityDefinition entityDef, String[] projections, RestrictionBuilder restriction, SOrder[] orderBy, Limits limits);
	public Collection<?> getByRestriction(EntityDefinition entityDef, RestrictionBuilder restriction, SOrder[] orderBy, Limits limits);
	public Collection<?> getByRestrictionAsMaps(EntityDefinition entityDef, RestrictionBuilder restriction, SOrder[] orderBy, Limits limits);	
	public Collection<?> getByAttribute(EntityDefinition entityDef, RestrictionAttribute attribute, SOrder[] orderBy, Limits limits);
	public Collection<?> getAll(EntityDefinition entityDef, SOrder[] orderBy);
	
	public boolean existsWithId(EntityDefinition entityDef, Serializable id);
	public boolean existsWithRestriction(EntityDefinition entityDef, RestrictionBuilder restriction);
	public Number count(EntityDefinition entityDef, String projection, RestrictionBuilder restriction);
	public Number count(EntityDefinition entityDef, RestrictionBuilder restriction);
	public Object getAggregate(EntityDefinition entityDef, Aggregate agg, String propertyName, RestrictionBuilder restriction);
	
	public Blob createBlob(Object... param);
	public Object execute(DBOperation operation);
	public Object executeInTransaction(Transaction operation);
}
